[Refactor] : J-POP 번역 dbArtistKoMap 초기화를 DB 직접 조회로 변경 (#199)#200
Conversation
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
/describe |
|
/review |
|
/improve |
Code Review by QodoNew Review StartedThis review has been superseded by a new analysisⓘ The new review experience is currently in Beta. Learn more |
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan Review Summary by QodoRefactor J-POP artist translation to use direct DB lookup
WalkthroughsDescription• Refactor dbArtistKoMap initialization to query DB directly instead of batch-based aggregation • Add new getArtistKoMapDB() function to load artist translations from database • Implement three-tier priority for artist translation: alias > DB > AI • Add separate counter and log prefix for DB-sourced artist translations • Synchronize runtime map with successful translations using first-seen principle Diagramflowchart LR
A["getArtistKoMapDB()"] -->|Load from DB| B["dbArtistKoMap"]
C["artistAlias"] -->|Priority 1| D["finalArtistKo"]
B -->|Priority 2| D
E["AI Translation"] -->|Priority 3| D
D -->|Update DB| F["Song Record"]
D -->|Sync Runtime| B
File Changes1. packages/crawling/src/cron/translationJpn.ts
|
Code Review by Qodo
1. Non-deterministic artist_ko pick
|
Code Review by Qodo
1. Non-deterministic artist_ko pick
|
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan PR Description updated to latest commit (9c13385)
|
| const { data, error } = await supabase | ||
| .from('songs') | ||
| .select('artist, artist_ko, song_tags!inner(tag_id)') | ||
| .eq('song_tags.tag_id', 101) | ||
| .not('artist_ko', 'is', null) | ||
| .limit(50000); | ||
|
|
||
| if (error) throw error; | ||
|
|
||
| const map = new Map<string, string>(); | ||
| for (const row of data) { | ||
| if (!row.artist || !row.artist_ko) continue; | ||
| if (!map.has(row.artist)) { | ||
| map.set(row.artist, row.artist_ko); | ||
| } |
There was a problem hiding this comment.
1. Non-deterministic artist_ko pick 🐞 Bug ≡ Correctness
getArtistKoMapDB()는 Map에 first-seen으로 artist_ko를 고정하지만 쿼리에 ORDER BY가 없어 동일 artist에 여러 artist_ko가 존재할 때 어떤 값이 선택될지 실행마다 달라질 수 있습니다. 이 값은 translationJpn.ts에서 AI 결과를 덮어써 artist_ko 재사용 일관성을 깨뜨릴 수 있습니다.
Agent Prompt
### Issue description
`getArtistKoMapDB()`는 "first-seen" 규칙을 구현하지만 쿼리 결과의 순서가 고정되어 있지 않아(ORDER BY 없음) 동일 artist에 여러 `artist_ko`가 있는 경우 어떤 값이 선택될지 비결정적입니다. 이 Map은 번역 시 AI 결과보다 우선 적용되므로, 실행마다 `artist_ko` 재사용 결과가 달라질 수 있습니다.
### Issue Context
- Map 구성은 `if (!map.has(row.artist)) map.set(...)` 형태로 첫 번째 행을 채택합니다.
- 하지만 Supabase 쿼리에 `.order(...)`가 없어 "첫 번째"의 의미가 불명확합니다.
### Fix Focus Areas
- packages/crawling/src/supabase/getDB.ts[121-136]
- packages/crawling/src/cron/translationJpn.ts[61-69]
### Suggested fix
- `getArtistKoMapDB()` 쿼리에 결정적 정렬을 추가하세요(예: `order('artist', { ascending: true })` 후 `order('updated_at', { ascending: true })` 또는 일관성 있는 tie-breaker).
- 가능하면 DB에서 artist 단위로 단일 row를 보장(뷰/RPC/unique constraint)하거나, 어떤 기준(최신/최초)을 채택할지 명시적으로 결정해 쿼리로 강제하세요.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
User description
📌 PR 제목
[Refactor] : J-POP 번역 dbArtistKoMap 초기화를 DB 직접 조회로 변경
📌 변경 사항
@/supabase/getDB에getArtistKoMapDB()추가tag_id=101+artist_ko IS NOT NULL로 distinct artist→artist_ko 를 DB 에서 직접 로드translationJpn.ts:artistKoCountMap) 로직 전부 제거dbArtistKoMap초기화를getArtistKoMapDB()호출로 단일화if (!has) set(finalArtistKo)로 런타임 맵 동기화 (alias/DB/AI 공통)[DB]로그 prefix 및usedDbArtist카운터 분리 추가💬 추가 참고 사항
artist_ko로 정규화되어 있어 first-seen 로직이 안전함PR Type
Enhancement
Description
Refactor
dbArtistKoMapinitialization to query DB directly instead of batch-based aggregationAdd
getArtistKoMapDB()function to load artist translations from databaseImplement runtime map synchronization with first-seen principle
Separate logging and metrics for DB-sourced artist translations
Diagram Walkthrough
File Walkthrough
translationJpn.ts
Integrate DB artist map and implement priority-based translationpackages/crawling/src/cron/translationJpn.ts
getArtistKoMapDBfunction for database-driven initializationusedDbArtistcounter to track DB-sourced translationsdbArtistKoMapby callinggetArtistKoMapDB()beforeprocessing
overwrite)
[ALIAS], DB[DB], and AI[OK]translations
getDB.ts
Add database function to load artist translation mappackages/crawling/src/supabase/getDB.ts
getArtistKoMapDB()function to fetch J-POP songs with non-nullartist_kotag_id=101(J-POP) andartist_ko IS NOT NULLartist
Mapfor efficient artist-to-translation lookup